package com.itheima.service.impl;


import com.itheima.dao.FakeDao;
import com.itheima.dao.UserFeignClient;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {

//    @Autowired
//    private FakeDao fakeDao;
    @Autowired
    private UserFeignClient userFeignClient;

//    @Autowired
//    private DiscoveryClient discoveryClient;
    private Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Override
    public List<User> queryUserByIds(List<Long> ids) {

        List<User> list = new ArrayList<>();
//        ids.forEach(id -> list.add(userFeignClient.queryUserById(id)));
//        List<User> list = userDao.queryUserById(ids);

        for (Long id : ids) {
            Long start = System.currentTimeMillis();
            User user = userFeignClient.queryUserById(id);
            list.add(user);
            Long end = System.currentTimeMillis();

            logger.info("本次查询：{}，用时{}ms",id,end - start);
        }

        return list;
    }
}
